home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / FrameAnim App ƒ / Setup.c < prev    next >
Encoding:
Text File  |  1994-11-06  |  4.6 KB  |  170 lines  |  [TEXT/KAHL]

  1. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. // • Program:    FrameAnim
  3. // • File:        Setup.c
  4. // •
  5. // • Copyright © 1993 by Scott B. Steinman, O.D., Ph.D. All Rights Reserved.
  6. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  7.  
  8. #include <Packages.h>
  9. #include "FrameAnim.h"
  10.  
  11. // • ------------------ External Globals ---------------------------------- 
  12.  
  13. extern CWindowPtr        gMainWindow;        // • From Main.c file
  14. extern GWorldPtr        gFrames[];            // • From Main.c file
  15. extern GDHandle            gDevice;             // • From Main.c file
  16. extern PaletteHandle    gPalette;            // • From Main.c file
  17. extern CTabHandle        gCTable;            // • From Main.c file
  18. extern Handle            gMenuBar;            // • From Main.c file
  19. extern Settings            gSettings;            // • From Main.c file
  20. extern Rect                gGlobBounds;         // • From Animation.c file
  21.  
  22. // •------------------- Static Variables ----------------------------------
  23.  
  24. CWindowRecord            sMainRecord;        // • Storage for window info 
  25.  
  26. // •------------------- Initialize Toolbox Managers -----------------------
  27.  
  28. void
  29. InitManagers( void )
  30. // •
  31. // • Used to initialize Toolbox managers
  32. {
  33.     short        i;
  34.  
  35.  
  36.     MaxApplZone();
  37.     
  38.     InitGraf( &thePort );        // • Initialize QuickDraw. 
  39.  
  40.     for (i = 0; i < 8; i++) 
  41.         MoreMasters();            // • Extra pointer blocks at bottom of heap 
  42.  
  43.     InitFonts();
  44.     FlushEvents( everyEvent, kRemoveAllEvents );    // • Clear out event queue 
  45.     InitWindows();
  46.     InitMenus();
  47.     TEInit();
  48.     InitDialogs( NullPointer );
  49.     InitAllPacks();
  50. }
  51.  
  52. // • ------------------ Get Number of Monitors ---------------------------- 
  53.  
  54. void
  55. GetNumMonitors( void )
  56. // •
  57. // • Finds number of monitors present in system.
  58. {
  59.     GDHandle    device = NullHandle;
  60.     
  61.     device = GetMainDevice();            
  62.     device = GetNextDevice( device );
  63.     if (device == NullHandle) {
  64.         gSettings.numMonitors = 1;
  65.         gSettings.displayMonitor = kMain;
  66.     }
  67.     else
  68.         gSettings.numMonitors = 2;
  69. }
  70.  
  71. // • ------------------ Prepare Animation Display Window ------------------ 
  72.  
  73. void
  74. SetUpWindows( void )
  75. // •
  76. // • Creates main output window
  77. {
  78.     Rect        boundingBox;
  79.     long        refVal;                    // • Reference value used by window manager 
  80.     short        typeOfW = 4;            // • Window type = noGrow document
  81.     Boolean        visible = true,            // • Window is shown 
  82.                 goAway = false;            // • Window has no close box 
  83.     
  84.     if (gSettings.numMonitors == 1) {
  85.         HLock( (Handle) GrayRgn );        // • If only one monitor, use its bounding box 
  86.         boundingBox = (**GrayRgn).rgnBBox;
  87.         HUnlock( (Handle) GrayRgn );    
  88.     }
  89.     else {
  90.         HLock( (Handle) gDevice );
  91.         boundingBox = (**gDevice).gdRect;    // • Get device's bounding box 
  92.         HUnlock( (Handle) gDevice );
  93.     }
  94.  
  95.     gMainWindow = (CWindowPtr) NewCWindow( (WindowRecord *) &sMainRecord, 
  96.      &boundingBox, "\pFrame Animation", visible, typeOfW, NullPointer, goAway, refVal );
  97.     if (gMainWindow == NullPointer)
  98.          ErrorHandler( kNoWindMsg, (char *) NilString, (char *) NilString, 
  99.           (char *) NilString );
  100.                  
  101.     // • Set up new palette and attach it to our window 
  102.     
  103.     InitPalette();
  104.     
  105.     // • Get position of center of window
  106.         
  107.     FindOrigin();
  108. }
  109.  
  110. // • ------------------ Prepare Menus ------------------------------------- 
  111.  
  112. void
  113. SetUpMenus( void )
  114. // •
  115. // • Set up the application menus using resources.
  116. {
  117.     gMenuBar = GetNewMBar( kMBarID );
  118.     SetMenuBar( gMenuBar );
  119.     
  120.     // • List desk accesories in Apple menu. 
  121.  
  122.     AddResMenu( GetMHandle( kAppleID ), 'DRVR' );    
  123.  
  124.     DrawMenuBar();
  125. }
  126.  
  127. // • ------------------ Prepare Palettes ---------------------------------- 
  128.  
  129. void
  130. InitPalette( void )
  131. // •
  132. // • Used to initialize color palette to be used 
  133. // • for our window and off-screen GWorlds.
  134. {
  135.     gCTable = GetCTable( kGrayCTableID );
  136.     DetachResource( gCTable ); 
  137.     (*gCTable)->ctFlags |= 0x4000;        // • Speeds up later CopyBits calls
  138.     gPalette = NewPalette( kNumColors, gCTable, pmTolerant+pmExplicit, 0 );
  139.     if (gPalette == NullHandle) 
  140.         ErrorHandler( kNoMemoryMsg, (char *) NilString, (char *) NilString, 
  141.          (char *) NilString );
  142.     NSetPalette( (WindowPtr) gMainWindow, gPalette, false );
  143.     ActivatePalette( (WindowPtr) gMainWindow );
  144.     ResetForeAndBackColors();        
  145. }
  146.  
  147. // • ------------------ Update Display Window Palette --------------------- 
  148.  
  149. void
  150. UpdateWindowColors( void )
  151. // •
  152. // • Sets window gray levels in palette.
  153. {
  154.     RGBColor        c;
  155.  
  156.     c.red = c.green = c.blue = gSettings.bkgndGray * 256;
  157.     SetEntryColor( gPalette, kPalBkgnd, &c );
  158.     SetEntryUsage( gPalette, kPalBkgnd, pmTolerant+pmExplicit, 0 );
  159.     c.red = c.green = c.blue = gSettings.targetGray * 256;
  160.     SetEntryColor( gPalette, kPalTarget, &c );
  161.     SetEntryUsage( gPalette, kPalTarget, pmTolerant+pmExplicit, 0 );
  162.     Palette2CTab( gPalette, gCTable );
  163.     
  164.     // • Reset window palette 
  165.     
  166.     NSetPalette( (WindowPtr) gMainWindow, gPalette, true );
  167.     ActivatePalette( (WindowPtr) gMainWindow );
  168.     ResetForeAndBackColors();        
  169. }
  170.